package com.zige.zige.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import android.util.Log;

public class LogUtils {
	private static final boolean DEBUG = true;

	public static void i(String TAG, String method, String msg) {
		logI(TAG, "[" + method + "]" + msg);
	}

	public static void i(String TAG, String msg) {

		logI(TAG, "[" + getFileLineMethod() + "]" + msg);

	}

	public static void i(String msg) {

		logI(_FILE_(), "[" + getLineMethod() + "]" + msg);

	}
	
	public static void i(HashMap<String, String> msg) {
		
		logI(_FILE_(), "[" + getLineMethod() + "]" + msg);

	}

	private static void logI(String tag, String msg) {
		if (DEBUG) {
			Log.d(tag, msg);
		}
	}

	public static void d(String TAG, String method, String msg) {
		logD(TAG, "[" + method + "]" + msg);
	}

	public static void d(String TAG, String msg) {

		logD(TAG, "[" + getFileLineMethod() + "]" + msg);

	}

	public static void d(String msg) {

		logD(_FILE_(), "[" + getLineMethod() + "]" + msg);

	}

	private static void logD(String tag, String msg) {
		if (DEBUG) {
			Log.d(tag, msg);
		}
	}

	public static void e(Exception e) {

		logE(_FILE_(), getLineMethod() + e.toString());

	}

	public static void e(String msg) {

		logE(_FILE_(), getLineMethod() + msg);

	}

	public static void e(String TAG, String msg) {

		logE(TAG, getLineMethod() + msg);

	}

	private static void logE(String tag, String msg) {
		if (DEBUG) {
			Log.e(tag, msg);
		}
	}

	private static String getFileLineMethod() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		StringBuffer toStringBuffer = new StringBuffer("[")
				.append(traceElement.getFileName()).append(" | ")
				.append(traceElement.getLineNumber()).append(" | ")
				.append(traceElement.getMethodName()).append("]");
		return toStringBuffer.toString();
	}

	private static String getLineMethod() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		StringBuffer toStringBuffer = new StringBuffer("[")
				.append(traceElement.getLineNumber()).append(" | ")
				.append(traceElement.getMethodName()).append("]");
		return toStringBuffer.toString();
	}

	private static String _FILE_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		return traceElement.getFileName();
	}

	private static String _FUNC_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
		return traceElement.getMethodName();
	}

	private static int _LINE_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
		return traceElement.getLineNumber();
	}

	private static String _TIME_() {
		Date now = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		return sdf.format(now);
	}
}
